package com.xinda.admin.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xinda.admin.dao.ProductMapper;
import com.xinda.admin.pojo.ProviderProduct;
import com.xinda.admin.vo.ProductListVo;

@Component("productService")
public class ProductServiceImpl implements IProductService{
	
	@Autowired
	ProductMapper productMapper;

	public List<ProviderProduct> queryProductes(int status, String productName) {
		
		ProductListVo productListVo = new ProductListVo();
		productListVo.setStatus(status);
		productListVo.setProductName(productName);
		
		return productMapper.selectProductes(productListVo);
	}

	public void updateOneProductStatus(int id, int status) {
		
		ProviderProduct product = new ProviderProduct();
		product.setId(id);
		product.setStatus(status);
		
		productMapper.updateOneStatus(product);
	}

	public void batchUpdateProductStatus(int[] ids, int status) {
		
		List<Integer> idslist = new ArrayList<Integer>();
		
		for (int i : ids){
			idslist.add(i);
		}
		
		ProductListVo productListVo = new ProductListVo();
		productListVo.setIds(idslist);
		productListVo.setStatus(status);
		
		productMapper.batchUpdateStatus(productListVo);
	}

	public ProviderProduct queryProductDetail(int id) {
		return productMapper.selectProductDetail(id);
	}

}
